package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.MemberOf;
import com.jeff.tianti.cms.dto.MemberOfQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author liuyi
 * @desc MemberOfDaoImpl类
 * @date 2019-06-19
 */

public class MemberOfDaoImpl extends CustomBaseSqlDaoImpl implements MemberOfDaoCustom {

    public PageModel<MemberOf> queryMemberOfPage(MemberOfQueryDTO memberOfQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append(" select t from MemberOf t where 1=1 ");
        if (memberOfQueryDTO != null) {
            String companyName = memberOfQueryDTO.getCompanyName();
            if (StringUtils.isNotBlank(companyName)) {
                hql.append(" and t.companyName like :companyName ");
                map.put("companyName", "%" + companyName + "%");
            }
            String phone = memberOfQueryDTO.getPhone();
            if (StringUtils.isNotBlank(phone)) {
                hql.append(" and t.phone like :phone ");
                map.put("phone", "%" + phone + "%");
            }
            String level = memberOfQueryDTO.getLevel();
            if (StringUtils.isNoneBlank(level)) {
                hql.append(" and t.memberType = :memberType ");
                map.put("memberType", level);
            }
        }
        hql.append(" order by t.createDate desc");
        return this.queryForPageWithParams(hql.toString(), map, memberOfQueryDTO.getCurrentPage(), memberOfQueryDTO.getPageSize());
    }

    public List<MemberOf> queryMemberOfList(MemberOfQueryDTO memberOfQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from MemberOf t ");
        return this.queryByMapParams(hql.toString(), map);
    }


}